package com.idea.zd.sys.train.collection;

import java.util.*;

public class QueueTest {


    public static void main(String [] args){
        //add()和remove()方法在失败的时候会抛出异常(不推荐)
        /**
         * 先进先出 FIFO
         */
       System.out.println("================================Queue=====================================");
       Queue queue = new PriorityQueue<>();
        queue.offer(1);
        queue.offer(2);
        queue.offer(3);
        System.out.println("元素值:"+queue);
        //获取元素不删除
        System.out.println("peek()第一个元素:"+queue.peek());
        System.out.println("长度:"+queue.size());
        //获取元素并删除
        System.out.println("poll()第一个元素:"+queue.poll());
        System.out.println("长度:"+queue.size());


        /**
         * PriorityQueue 按元素大小先出
         */
        /*
        System.out.println("================================PriorityQueue=====================================");
        PriorityQueue priorityQueue = new PriorityQueue();
        priorityQueue.offer(3);
        priorityQueue.offer(2);
        priorityQueue.offer(1);
        //获取元素不删除
        System.out.println(priorityQueue.peek());
        System.out.println(priorityQueue.size());
        //获取元素并删除
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.size());*/



        /**
         * Deque 双端队列
         */
        /*
        System.out.println("================================Deque 双端队列=====================================");

        Deque queue = new ArrayDeque();
        queue.offer("111");
        queue.offer("222");
        System.out.println("getFirst()第一个元素:"+queue.getFirst());
        System.out.println("peek()第一个元素:"+queue.poll());
        System.out.println("peek()第二个元素:"+queue.poll());
        queue.offerFirst("000");
        System.out.println("getFirst()第一个元素:"+queue.getFirst());
        System.out.println("最后一个元素:"+queue.getLast());
        queue.offerLast("333");
        System.out.println("最后一个元素:"+queue.getLast());*/



        /**
         * Deque 栈
         */
       /* System.out.println("================================Deque 栈=====================================");
        Deque stack = new ArrayDeque();
        stack.push("1111");
        stack.push("2222");
        System.out.println("peekFirst()第一个元素:"+stack.peekFirst());
        System.out.println("getLast()第一个元素:"+stack.getLast());
        System.out.println("getFirst()第一个元素:"+stack.poll());
        System.out.println("getFirst()第二个元素:"+stack.poll());*/

    }
}
